﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HFController;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using System.Web.Services;
namespace HFWebApp.AjaxSource
{
    /// <summary>
    /// CheckUserRemember 的摘要说明
    /// </summary>
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class CheckUserRemember : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            HFModel.ResultModel result = new HFModel.ResultModel();
            BagePages bp = new BagePages();
            string TypeID = bp.GetQuery("TypeID");
            if (TypeID == "0")
            {
                if (context.Request.Cookies["isrember"] != null)
                {
                    result.isTrue = true;
                    result.Message = context.Request.Cookies["username"].Value + "," + context.Request.Cookies["password"].Value + "," + context.Request.Cookies["isrember"].Value;
                }
                else
                {
                    result.isTrue = false;
                    result.Message = "";
                }
            }
            else {
                hf.Model.User user = bp.getLoginAccount();
                hf.Model.Lawyer lawyer = bp.getLoginLawyer();
                if (user != null)
                {
                    result.isTrue = true;
                    result.Message = user.UID + "|" + user.Point.ToString();
                }
                else if (lawyer != null)
                {
                    result.isTrue = true;
                    result.Message = lawyer.UID + "|" + lawyer.Point.ToString();
                }
                else
                {
                    result.isTrue = false;
                }
            }

            context.Response.Write(this.getJSONResult(result));
            context.Response.End();
        }

        protected string getJSONResult(HFModel.ResultModel result)
        {
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer(new SimpleTypeResolver());
            return jsSerializer.Serialize(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}